package com.mall.service.item;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.item.MallItemService;
import com.mall.custom.dao.read.MallItemReadMapper;
import com.mall.custom.dao.write.MallItemWriteMapper;
import com.mall.pojo.MallItem;
import com.mall.pojo.MallItemExample;
import com.mall.pojo.MallItemExample.Criteria;

@Service
public class MallItemServiceImpl implements MallItemService {

	@Autowired
	private MallItemReadMapper mallItemReadMapper;
	@Autowired
	private MallItemWriteMapper mallItemWriteMapper;

	@Override
	public MallItem getMallItemById(Long mallItemId) {
		if(mallItemId == null || mallItemId <= 0){
			return null;
		}
		return this.mallItemReadMapper.selectByPrimaryKey(mallItemId);
	}

	@Override
	public int modifyMallItemByPrimarykey(MallItem mallItem) {
		mallItem.setGmtModify(new Date());
		return this.mallItemWriteMapper.updateByPrimaryKey(mallItem);

	}

	@Override
	public List<MallItem> getMallItemListByExample(MallItemExample example) {
		return this.mallItemReadMapper.selectByExample(example);
	}

	@Override
	public List<MallItem> getMallItemByIds(List<Long> mallItemIdList) {
		MallItemExample example = new MallItemExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdIn(mallItemIdList);
		return this.getMallItemListByExample(example);
	}

	@Override
	public int insertMallItem(MallItem mallItem) {
		mallItem.setGmtCreate(new Date());
		mallItem.setGmtModify(new Date());
		return this.mallItemWriteMapper.insert(mallItem);
	}

	@Override
	public int updateMallItemByIds(List<Integer> ids) {
		return this.mallItemWriteMapper.updateItemByIds(ids);
	}

}
